package com.example.demo.service.rp.impl;

import com.example.demo.entity.CollectionName;
import com.example.demo.entity.Result;
import com.example.demo.entity.power.Power;
import com.example.demo.service.rp.RolePowerService;
import com.example.demo.utils.DateUtil;
import com.example.demo.utils.StringUtil;
import org.apache.http.client.utils.DateUtils;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @description: 角色-权限
 * @author: cj
 * @create: 11-02-28 11:03:10
 */
@Service
public class RolePowerServiceImpl implements RolePowerService {
    @Resource
    MongoTemplate mongoTemplate;

    /**
     * 创建权限
     *
     * @param power 权限信息
     * @return 成功或者失败
     */
    @Override
    public Result createPower(Power power) {
        //设置创建时间
        power.setTime( DateUtil.dateToString( new Date() ) );
        //默认状态为 1
        power.setState( "1" );
        String name = power.getName();
        if (StringUtil.isEmpty( name )) {
            throw new RuntimeException( "权限名称不能为空" );
        }
        Power save = mongoTemplate.save( power, CollectionName.USER_POWER );
        return Result.ok( "操作成功", save );
    }
}
